package com.usian.behavior.service

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper
import com.baomidou.mybatisplus.core.toolkit.Wrappers
import com.usian.behavior.mapper.ApBehaviorEntryMapper
import com.usian.common.BaseServiceImpl
import com.usian.model.behavior.pojos.ApBehaviorEntry
import org.springframework.stereotype.Service

@Service
open class ApBehaviorEntryServiceImpl : BaseServiceImpl<ApBehaviorEntryMapper, ApBehaviorEntry>() {
    open fun findByUserIdOrEquipmentId(userId: Int, equipmentId: Int = 0): ApBehaviorEntry? {
        return if (userId != null) getOne(getW(userId, 1)) else {
            if (equipmentId != null && equipmentId != 0) {
                getOne(getW(equipmentId,0))
            } else null
        }
    }

    private fun getW(id: Int, type: Int): QueryWrapper<ApBehaviorEntry> = Wrappers.query<ApBehaviorEntry>().eq("entry_id", id).eq("type", type)
}